package vn.nt.healthcare.server.ws.util;

import java.util.Calendar;
import java.util.Date;

public class DateUtil {
	
	public static Date getStartOfDay(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		int year = calendar.get(Calendar.YEAR);
		int month = calendar.get(Calendar.MONTH);
		int day = calendar.get(Calendar.DATE);
		calendar.set(year, month, day, 0, 0, 0);
		return calendar.getTime();
	}

	public static Date getEndOfDay(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		int year = calendar.get(Calendar.YEAR);
		int month = calendar.get(Calendar.MONTH);
		int day = calendar.get(Calendar.DATE);
		calendar.set(Calendar.MILLISECOND, 999);
		calendar.set(year, month, day, 23, 59, 59);
		return calendar.getTime();
	}
	
	public static Date getEndOfMorning(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		int year = calendar.get(Calendar.YEAR);
		int month = calendar.get(Calendar.MONTH);
		int day = calendar.get(Calendar.DATE);
		calendar.set(Calendar.MILLISECOND, 999);
		calendar.set(year, month, day, 11, 59, 59);
		return calendar.getTime();
	}
	
	public static Date getStartOfAfternoon(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		int year = calendar.get(Calendar.YEAR);
		int month = calendar.get(Calendar.MONTH);
		int day = calendar.get(Calendar.DATE);
		calendar.set(Calendar.MILLISECOND, 999);
		calendar.set(year, month, day, 12, 00, 00);
		return calendar.getTime();
	}	
}
